package logic

import (
	"cart_srv/pb/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CheckLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckLogic {
	return &CheckLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CheckLogic) Check(req *types.CheckCartRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	userId := 1
	checked, err := l.svcCtx.CartSrv.CartChecked(l.ctx, &cart.CartCheckedRequest{
		UserId:  int64(userId),
		Checked: req.Checked,
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "操作成功",
		Data: map[string]interface{}{
			"checked": checked,
		},
	}, nil
}
